// https://leetcode.cn/problems/h-index-ii/
// Created by ade on 2022/9/14.
//
#include <iostream>
#include <vector>
#include <numeric>
#include <cmath>
#include <algorithm>

using namespace std;

class Solution {
public:
    int hIndex(vector<int> &citations) {
        int len = citations.size();
        int l = 0, r = len - 1;
        while (l < r) {
            swap(citations[l], citations[r]);
            l++;
            r--;
        }
        int i = 0;
        for (i = 0; i < citations.size(); i++) {
            if (citations[i] < i + 1) return i;
        }
        return i;
    }
};


int main() {
    Solution so;
    vector<int> c = {0, 1, 3, 5, 6}; // 0 1 3 5 6
    cout << so.hIndex(c);
    return 0;
}
